import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { environment } from 'src/environments/environment';

@Injectable({
  providedIn: 'root'
})
export class MenuService {
  private menuItems: any[] = [];
  data='/Menu'
  constructor(private http: HttpClient) {
    const storedMenuItems = localStorage.getItem('menuItems');
    if (storedMenuItems) {
      this.menuItems = JSON.parse(storedMenuItems);
    }
  }
  GetAllMenus(){
    const GetAllMenus = '/GetAllMenus';
    return this.http.get(environment.apiUrl+this.data+GetAllMenus);
  }// 获取所有菜单
  GetMenusByRole(roleId:any){
    const GetMenusByRole = '/GetMenusByRoleId';
    return this.http.get(environment.apiUrl+this.data+GetMenusByRole,{params:{roleId}});
  }// 根据角色获取菜单
  UpdateRoleMenus(roleId:any,data:any){
    const UpdateRoleMenus = '/UpdateRoleMenus';
    return this.http.post(environment.apiUrl+this.data+UpdateRoleMenus,data,{params:{roleId}});
  }// 更新角色菜单
  setMenuItems(menuItems: any[]): void {
    this.menuItems = menuItems;
    localStorage.setItem('menuItems', JSON.stringify(menuItems));
  }
  getMenuItems(): any[] {
    return this.menuItems;
  }
  UpdateAppRoleMenus(roleId:any,data:any){
    const UpdateAppRoleMenus = '/UpdateAppRoleMenus';
    return this.http.post(environment.apiUrl+this.data+UpdateAppRoleMenus,data,{params:{roleId}});
  }// 更新角色菜单
  GetAllAppMenus(){
    const GetAllAppMenus = '/GetAllAppMenus';
    return this.http.get(environment.apiUrl+this.data+GetAllAppMenus);
  }// 获取所有APP菜单
  GetAppMenusByRoleIdId(roleId:any){
    const GetAppMenusByRoleIdId = '/GetAppMenusByRoleIdId';
    return this.http.get(environment.apiUrl+this.data+GetAppMenusByRoleIdId,{params:{roleId}});
  }// 根据角色获取APP菜单
}
